package MementoPattern.demo2;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author： pang-yun
 * @date： 2022-01-06 10:59
 * 功能目的 ：用于  监控者  保存多个 memento 状态
 */

public class Caretaker {
    private static Map mementoHashMap = new ConcurrentHashMap<Integer, Memento>();
    private AtomicInteger integer =new AtomicInteger();
    private Caretaker() {
    }

    private static Caretaker instance = new Caretaker();

    public static Caretaker getInstance() {
        return instance;
    }

    public void add (Memento memento){
        mementoHashMap.put(integer.getAndIncrement(),memento);
    }

    public void print(){
        mementoHashMap.entrySet().stream().forEach(System.out::println);
    }
}
